<style type="text/css" title="currentStyle">
	@import "../media/css/demo_page.css";
	@import "../media/css/demo_table_jui.css";
	@import "../examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css";
	@import "media/css/TableTools_JUI.css";
</style>
<script type="text/javascript" charset="utf-8" src="../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready( function () {
		$('#example').dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"sDom": 'Tlfrtip',
			"oTableTools": {
				"aButtons": [
					"copy", "csv", "xls", "pdf", "print",
					{
						"sExtends":    "collection",
						"sButtonText": "Save",
						"aButtons":    [ "csv", "xls", "pdf" ]
					}
				]
			}
		} );
	} );
</script>
<?php
if($recordUserInfo[ci_clientType] == "Client" && $recordUserInfo[ui_isAdmin] == "1")
{
	$devices_query =  "SELECT * FROM tb_deviceinfo,tb_client_subscription WHERE tcs_isActive = 1 AND tcs_deviceId = di_id AND di_clientId =".$_SESSION[clientID]." AND di_status = 1 ORDER BY di_deviceName,di_deviceId ASC";
}
else if($recordUserInfo[ci_clientType] == "Client" && $recordUserInfo[ui_isAdmin] == "0" && $recordUserInfo[ui_roleId] == "1")
{
	$devices_query = "SELECT * FROM tb_deviceinfo,tb_client_subscription WHERE tcs_isActive = 1 AND tcs_deviceId = di_id AND di_status = 1 AND di_clientId=".$_SESSION[clientID]." AND di_assignedUserId = ".$_SESSION[userID]." ORDER BY di_deviceName,di_deviceId ASC";
}
//echo $devices_query;
//$devices_query =  "SELECT * FROM tb_deviceinfo WHERE di_clientId =".$_SESSION[clientID]." AND di_status = 1 ORDER BY di_deviceName,di_deviceId ASC";
$devices_resp = mysql_query($devices_query);	
?>
<script type="text/javascript" language="javascript">
function showFormDiv()
{
	if(document.getElementById('formDiv').style.display=='none')
	{
		document.getElementById('formDiv').style.display = 'block';
		document.getElementById('shLink').innerHTML = "Hide Form";
	}
	else
	{
		document.getElementById('formDiv').style.display = 'none';
		if(document.getElementById('shLink'))
		document.getElementById('shLink').innerHTML = "Show Form";
	}
}
function showPreloader()
{
	var returnVal = validateMapReport()
	if(returnVal == 1)
	{
		document.getElementById('popup_div').innerHTML = '<div id="loading_txt" >Loading...</div>';
		document.frm_map_filter.submit();
	}
}

function hidePreLoader()
{
	document.getElementById('popup_div').innerHTML = '&nbsp;';
}

function validateMapReport()
{
  if(document.getElementById('map_device_id').value== 0 )
  {
   alert("Select Device"); 
   document.getElementById('map_device_id').focus();
   return 0;  
  }
  
  if(document.getElementById('from_date').value=='')
  { alert("Select From Date"); document.getElementById('from_date').focus();  return 0;  }
  
  if(document.getElementById('to_date').value=='')
  { alert("Select To Date");  document.getElementById('to_date').focus(); return 0; }
  
  
	 var t1=document.getElementById('from_date').value ;
        var t2=document.getElementById('to_date').value;

        var one_day=1000*60*60*24; 
		var x=t1.split("-");     
        var y=t2.split("-");
        var date1=new Date(x[2],(x[1]-1),x[0]);
  
        var date2=new Date(y[2],(y[1]-1),y[0]);
        var month1=x[1]-1;
        var month2=y[1]-1;
        var diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day)); 
         
		 if(diff < 0){
       alert("From Date should be prior to To Date."); document.getElementById('to_date').select();return 0;

		 }
	
	
	return 1;
	
}

function sendCSVData()
{
//alert(c1);
document.frmTripData.submit();
//	window.location.href='export.php?csvData='+c1+'&frdate='+c2+'&frtime='+c3+'&totime='+c4+'&vehino='+c5;
	//document.write('export.php?csvData='+c1+'&frdate='+c2+'&frtime='+c3+'&totime='+c4+'&vehino='+c5);
}
function showMsgDiv(msgDiv)
{
	if(document.getElementById(msgDiv).style.display== 'none')
		document.getElementById(msgDiv).style.display = 'block';
	else
	document.getElementById(msgDiv).style.display = 'none';
}
$(function() {
	$( "#from_date" ).datepicker({
		changeMonth: true,
		changeYear: true,
		maxDate: 0,
		showOn: "button",
		buttonImage: "images/calendar.gif",
		buttonImageOnly: true,
		dateFormat : "dd-mm-yy"
	});
});
$(function() {
	$( "#to_date" ).datepicker({
		changeMonth: true,
		changeYear: true,
		maxDate: 0,
		showOn: "button",
		buttonImage: "images/calendar.gif",
		buttonImageOnly: true,
		dateFormat : "dd-mm-yy"
	});
});
</script>

<div id="formDiv">
<form id="frm_map_filter" name="frm_map_filter" method="post" action="" onsubmit="return validateMapReport();">      	 
<table class="gridform_final">
<tr><th colspan="9">Mail Alert Report</th></tr>
  <tr>
    <td width="13%" align="right"><span class="form_text">Select Device&nbsp;</span></td>
    <td width="20%" align="left" colspan="3">
        <select name="map_device_id" id="map_device_id" tabindex="1" style="width:100%" onchange="document.frm_map_filter.txtVehicleName.value = this.options[selectedIndex].text">
        <option value="0">Select Device</option>
         <?php 
		while($devices_fetch = @mysql_fetch_assoc($devices_resp)) 
		{ 
			$renewDate = date("d-m-Y",strtotime("-1 days ".$devices_fetch[tcs_renewalDateTo]));
			//echo $date_offline." <= ".date("d-m-Y",strtotime($renewDate))."<br>";
			if(strtotime(date('d-m-Y')) <= strtotime($renewDate))
			{
			if($devices_fetch[di_deviceName])
				$devName = $devices_fetch[di_deviceName];
			else
				$devName = $devices_fetch[di_deviceId];
        ?>
        <option value="<?php echo $devices_fetch[di_id]."#".$devices_fetch[di_imeiId]; ?>" 
        <?php if($_POST[map_device_id] == $devices_fetch[di_id]."#".$devices_fetch[di_imeiId]) echo "selected"; ?>><?php echo $devName; ?></option>
        <?php } } ?>		
        </select>
        <input type="hidden" name="txtVehicleName" id="txtVehicleName" />
        <input type="hidden" name="curdate" id="curdate" value="<?php echo date('Y-m-d'); ?>" />
    </td>
    <td width="10%" align="right"><span class="form_text">From Date</span></td>
    <td width="13%" align="left">
    <input type="text" name="from_date" id="from_date" readonly="true" size="12" tabindex="2" value="<?php if(isset($_POST[from_date])) echo $_POST[from_date]; else echo date("d-m-Y"); ?>" style="width:80%;"/>
    </td>
    <td width="10%" align="right"><span class="form_text">To Date</span></td>
    <td width="13%">
    <input type="text" name="to_date" id="to_date" size="12" style="width:80%;" tabindex="4" readonly="true" value="<?php if(isset($_POST[to_date])) echo $_POST[to_date]; else echo date("d-m-Y"); ?>" />&nbsp;
    </td>
    <td width="15%" style="text-align:center">
    <input type="button" name="map_filter_btn"   value="Filter" class="save_btn" tabindex="6"  onclick="showPreloader();"/>
    <input type="hidden" name="map_filter_btn" value="Filter" />
    <input type="button" name="map_cancel_btn" id="map_cancel_btn" value="Reset" class="save_btn" onclick="location.href='index.php?ch=mailreport';" tabindex="7" /> 
   </td>
  </tr>
</table>
</form>
</div>	
<div id="popup_div" style=" display:block; border:0px;" >

</div>
<?php
if(isset($_POST[map_filter_btn]) && $_POST[map_filter_btn]!='')
{
//print_r($_POST);

$sdate = date("Y-m-d",strtotime($_POST[from_date]));
$edate = date("Y-m-d",strtotime($_POST[to_date]));
$srcData = explode("#",$_POST[map_device_id]);

?>
<table cellpadding="0" cellspacing="0" border="0" class="gridform_final" id="example">      
  <thead>
  <tr>
	    <th width="5%">#</th>
        <th width="10%">Delivery Date</th>
        <th width="10%">Delivery Time</th>
        <th width="10%">Mail ID</th>
        <th width="15%">Device Name</th>
        <th>Message</th>
    </tr>
 </thead>
 <tbody>
<?php
$sql = "SELECT * FROM tb_mail_info,tb_deviceinfo where tmi_deviceId = di_id AND di_id = ".$srcData[0]." AND ( tmi_createDate like '".$sdate."%' OR tmi_createDate like '".$edate."%')";
//$sql = "SELECT * FROM tb_mail_info where ( tmi_createDate like '".$sdate."%' OR tmi_createDate like '".$edate."%') limit 0,10";
$rows = $db->query($sql);
if($db->affected_rows > 0)
{
	$i=0;
	while ($record = $db->fetch_array($rows)) 
	{
		if($record[di_deviceName])
			$devName = $record[di_deviceName];
		else
			$devName = $record[di_deviceId]; 
			
		?>		
		 <tr <?php if($i % 2 == 0) { echo 'class="odd_row"';} else { echo 'class="even_row"'; } ?> >
		   <td valign="top"><?php echo $i+1; ?></td>
		   <td valign="top"><?php echo date('d-m-Y',strtotime($record[tmi_createDate])); ?></td>			   
		   <td valign="top"><?php echo date("H:i:s A",strtotime($record[tmi_createDate])); ?></td>
           <td valign="top"><?php echo $record[tmi_email]; ?></td>
		   <td valign="top"><?php echo $devName; ?></td>
		   <td valign="top">
           <?php echo strip_tags(urldecode($record[tmi_message])); ?>
		   <!--<img src="images/mesg_icon.png" width="55" height="45" border="0" align="Message" title="Message" style="cursor:pointer;" onmouseover="showMsgDiv('mesgdiv_<?php echo $i;?>')" onmouseout="showMsgDiv('mesgdiv_<?php echo $i;?>')"/>
		   <div id="mesgdiv_<?php echo $i;?>" style="position:fixed; margin-bottom:0px; margin-left:-90%; margin-top:0px; display:none; z-index:999">
		   <?php echo urldecode($record[tmi_message]); ?>
		   </div>-->
		   </td>
		 </tr>
		   <?php 
		  $i++;
	}  
}
?>
</tbody>
</table>
<?php
  
}///end of post

?> 

